package com.wl.eb.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wl.eb.service.IndexService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.Map;

@Controller
@RequestMapping("/index")
public class IndexController {

    @Resource
    private IndexService indexService;


    @GetMapping("/index")
    public String index(Model model,
                        @RequestParam(value = "page",defaultValue = "1") int page){
        System.out.println("====进入IndexController的index方法,page="+page);
        //1、查看首页需要展示的数据
        Map<String,Object> result=indexService.index(page);
        System.out.println("====result:==="+result);

        //2、将数据放到model
        model.addAttribute("productpage",(Page)result.get("Productpage"));
        model.addAttribute("newspage",(Page)result.get("Newspage"));
        model.addAttribute("ebCommentPage",(Page)result.get("ebCommentPage"));
//        model.addAttribute("bigs",(List)result.get("bigs"));
//        model.addAttribute("smalls",(List)result.get("smalls"));
        //3、返回view---视图  html
       return "index";
    }

}
